package com.hspedu.homework;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/10
 * @time 17:57
 */
public class Homework01 {
    public static void main(String[] args) {
        News n1 = new News("新冠确诊病例超千万，数百万印度教信徒赴恒河“圣浴”引民众担忧");
        News n2 = new News("男子突然想起2个月前钓的鱼还在网兜里，捞起一看赶紧放生");
        List list = new ArrayList();
        list.add(n1);
        list.add(n2);
        String newTile = null;
        for (int i = list.size() - 1; i >= 0 ; i--) {
            if (n1.getClass() == list.get(i).getClass()){
                if (((News) (list.get(i))).getTitle() == null){
                    System.out.println("");
                }
                if (((News) (list.get(i))).getTitle().length() > 15){
                     newTile = ((News) (list.get(i))).getTitle().substring(0, 15)
                            +"...";
                }
            }
            System.out.println(newTile);
        }
    }
}

class News{
    private String title;
    private String content;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "News{" +
                "title='" + title + '\'' +
                ", content='" + content + '\'' +
                '}';
    }

    public News(String title) {
        this.title = title;
    }
}
